#include <REGX52.H>
#include <intrins.h>
int S = 0,time;					
sbit T=P1^2;
sbit E=P1^1;
int dat[9];
void Delay(unsigned int xms)
{
	unsigned char i, j;
	while(xms--)
	{
		i = 2;
		j = 239;
		do
		{
			while (--j);
		} while (--i);
	}
}
void Delay10us(void)	//@12.000MHz
{
	unsigned char data i;

	_nop_();
	_nop_();
	i = 27;
	while (--i);
}

void SG(int a,int b)
{
	unsigned char Tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x40};
  unsigned char Count[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
	P2=Count[a];
	P0=~Tab[b];
	Delay(6);
}

void Time0Init()
{
	TMOD=0x01;
	TH0=0;
	TL0=0;	
	EA=1;
	TR0=0;
}
void count()
{
	T=1;
	_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
	T=0;
	while(!E);TR0=1;
	while(E);	TR0=0;
	time=TH0*256+TL0;
	TH0=0;
	TL0=0;	
	S=(int)(time*1.7)/100;
	
	dat[0]=S/100;S=S%100;
	dat[1]=S/10;S=S%10;
	dat[3]=S;
}

void main()
{
	Time0Init();
	while(1)
	{
		count();
		SG(0,dat[0]);
		SG(1,dat[1]);
		SG(2,dat[2]);
	}
}